@extends('admin.main')
@section('content')
    <div class="admin-content">
        <div class="am-cf am-padding am-padding-bottom-0">
            <div class="am-fl am-cf">
                <strong class="am-text-primary am-text-lg">后台设置</strong> /
                <small>员工资料</small>
            </div>
        </div>
        <hr>
        <div class="am-g">
            @include('admin.layouts.adminInfo')
            <div class="am-u-sm-12 am-u-md-8 am-u-md-pull-4">
                <form action="{{$prefix_url}}{{isset($data)?'/'.$data->id:''}}"
                      class="am-form" method="POST" enctype="multipart/form-data">
                    {{csrf_field()}}
                    <input type='hidden' name='_method' value='POST'/>
                    <input type='hidden' name='uid' value='{{$uid}}'/>
                    <div class='am-form-group'>
                        <label>真实姓名：</label>
                        <input type="text" name="realname" placeholder="真实姓名" minlength='1' maxlength='20' required value="{{isset($data)?$data->realname:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>员工类型：</label>
                        <select name="cate" required>
                            <option value="1" {{(isset($data)&&$data->cate==1)?'selected':''}}>工厂员工</option>
                            <option value="2" {{(isset($data)&&$data->cate==2)?'selected':''}}>公司员工</option>
                        </select>
                    </div>
                    <div class='am-form-group'>
                        <label>职位选择：</label>
                        <select name="job" required>
                            {{--<option value="0">选择</option>--}}
                        </select>
                        <input type="hidden" id="job" value="{{isset($data)?$data->job:0}}">
                    </div>
                    <div class='am-form-group'>
                        <label>员工性别：</label>
                        <select name="sex" required>
                            <option value="1" {{(isset($data)&&$data->sex==1)?'selected':''}} {{(isset($data)&&$data->sex==1)?'selected':''}}>男</option>
                            <option value="2" {{(isset($data)&&$data->sex==2)?'selected':''}}>女</option>
                        </select>
                    </div>
                    <div class='am-form-group'>
                        <label>出生：</label>
                        <input type="text" name="birthday" placeholder="出生日期" class="doc-datepicker" readonly value="{{isset($data)?$data->birthday:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>员工学历：</label>
                        <select name="education" required>
                            @foreach($edus as $key => $edu)
                            <option value="{{$key}}" {{(isset($data)&&$data->education==$key)?'selected':''}}>{{$edu}}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class='am-form-group'>
                        <label>身高：</label>
                        <input type="text" name="weight" placeholder="身高，cm" pattern="^\d\d\d$" value="{{isset($data)?$data->weight:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>政治面貌：</label>
                        <select name="political_status" required>
                            @foreach($politics as $key2 => $politic)
                                <option value="{{$key2}}" {{(isset($data)&&$data->political_status==$key2)?'selected':''}}>{{$politic}}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class='am-form-group'>
                        <label>籍贯：</label>
                        <input type="text" name="native_place" placeholder="籍贯，如中国" minlength="2" value="{{isset($data)?$data->native_place:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>民族：</label>
                        <input type="text" name="nationality" placeholder="民族" minlength="1" value="{{isset($data)?$data->nationality:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>婚姻：</label>
                        <select name="marriage" required>
                            @foreach($marrys as $key3 => $marry)
                                <option value="{{$key3}}" {{(isset($data)&&$data->marriage==$key3)?'selected':''}}>{{$marry}}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class='am-form-group'>
                        <label>身份证号码：</label>
                        <input type="text" name="idcard" placeholder="身份证号码" minlength="18" maxlength="20" value="{{isset($data)?$data->idcard:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>住宿情况：</label>
                        <input type="text" name="house" placeholder="住宿情况"  value="{{isset($data)?$data->house:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>形象照：</label>
                        @if(isset($data) && $data->image
                            && file_exists(ltrim($data->image,'/')))
                            (上传图片将覆盖当前图片)
                        @endif
                        <input type="file" name="image"
                               style="padding:5px;width:100%;border:1px solid #cccccc;background:#f0f0f0;">
                        @if(isset($data) && $data->image
                            && file_exists(ltrim($data->image,'/')))
                            <p>当前照片：</p>
                            <img src="{{$data->image}}" width="500">
                        @endif
                    </div>
                    <div class='am-form-group'>
                        <label>身份证正面：</label>
                        @if(isset($data) && $data->sfzzm
                            && file_exists(ltrim($data->sfzzm,'/')))
                            (上传图片将覆盖当前图片)
                        @endif
                        <input type="file" name="sfzzm"
                               style="padding:5px;width:100%;border:1px solid #cccccc;background:#f0f0f0;">
                        @if(isset($data) && $data->sfzzm
                            && file_exists(ltrim($data->sfzzm,'/')))
                            <p>当前照片：</p>
                            <img src="{{$data->sfzzm}}" width="500">
                        @endif
                    </div>
                    <div class='am-form-group'>
                        <label>身份证反面：</label>
                        @if(isset($data) && $data->sfzfm
                            && file_exists(ltrim($data->sfzfm,'/')))
                            (上传图片将覆盖当前图片)
                        @endif
                        <input type="file" name="sfzfm"
                               style="padding:5px;width:100%;border:1px solid #cccccc;background:#f0f0f0;">
                        @if(isset($data) && $data->sfzfm
                            && file_exists(ltrim($data->sfzfm,'/')))
                            <p>当前照片：</p>
                            <img src="{{$data->sfzfm}}" width="500">
                        @endif
                    </div>
                    <div class='am-form-group'>
                        <label>户口地址：</label>
                        <input type="text" name="household_address" placeholder="户口地址" value="{{isset($data)?$data->household_address:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>居住地址：</label>
                        <input type="text" name="residential_address" placeholder="居住地址" value="{{isset($data)?$data->residential_address:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>紧急联系人：</label>
                        <input type="text" name="contact_person" placeholder="紧急联系人" value="{{isset($data)?$data->contact_person:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>紧急联系人号码：</label>
                        <input type="text" name="contact_phone" placeholder="紧急联系人号码" value="{{isset($data)?$data->contact_phone:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>希望薪资：</label>
                        <input type="text" name="salary" placeholder="希望薪资" pattern="\d+" value="{{isset($data)?$data->salary:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>专业技能：</label>
                        <br>
                        @if(count($skills))
                        @foreach($skills as $skill)
                            <label>
                                <input type="checkbox" name="skills[]"
                                       value="{{$skill['id']}}"
                                       {{(isset($data)&&in_array($skill['id'],$data->skills))?'selected':''}}
                                >
                                {{$skill['name']}}
                            </label>
                            &nbsp; &nbsp;
                        @endforeach
                        @endif
                    </div>
                    <div class='am-form-group'>
                        <label>兴趣爱好：</label>
                        <br>
                        @if(count($hobbys))
                        @foreach($hobbys as $hobby)
                            <label>
                                <input type="checkbox" name="hobbys[]"
                                       value="{{$hobby['id']}}"
                                       {{(isset($data)&&in_array($hobby['id'],$data->hobbys))?'selected':''}}
                                >
                                {{$hobby['name']}}
                            </label>
                            &nbsp; &nbsp;
                        @endforeach
                        @endif
                    </div>
                    <button type='button' class='am-btn am-btn-primary'
                            onclick='history.go(-1);'>返回</button>
                    <button type='submit' class='am-btn am-btn-primary'>
                        保存更新</button>
                </form>
                <br><br>
            </div>
        </div>
    </div>

    <script>
        //日期组件
        $(function() {
            $('.doc-datepicker').datepicker().
            on('changeDate.datepicker.amui', function(event) {
                console.log(event.date);
            });
        });
        (function(){
            getJobsByStaffType(1);
        })();
        /**
         * 工作岗位获取
         * */
        $("select[name='cate']").on('change',function(){
            var cate = $("select[name='cate']").val();
            getJobsByStaffType(cate);
        });
        //通过员工类型，获取岗位列表
        function getJobsByStaffType(cate){
            console.log(cate);
            var job = $('#job').val();
            var formData = {
                staffType:cate
            };
            $.ajaxSetup({
                headers: { 'X-CSRF-TOKEN':$("input[name='_token']").val() }
            });
            $.ajax({
                type:'post',
                dataType:'json',
                url:'/mcadmin/basic/job/jobsbystafftype',
                data:formData,
                success:function(res){
                    //console.log(res); return
                    if (res.code!=0) {
                        console.log(res.msg);
                        return
                    }
                    console.log(res.data);
                    var resData = res.data;
                    var i, h = '';
                    if (resData.length > 0) {
                        for (i=0;i<resData.length-1;i++) {
                            h += '<option value="'+resData[i].id+'" ';
                            if (resData[i].id==job) {
                                h += 'selected';
                            }
                            h += '>';
                            h += resData[i].name+'</option>';
                        }
                    }
                    $("select[name='job']").html(h);
                },
                error:function(){
                    console.log('操作失败！');
                }
            });
        }
    </script>
@stop